class Solution
{
public:
    vector<string> summaryRanges(vector<int> &nums)
    {
        vector<string> result;
        int n = nums.size();
        if (n == 0)
        {
            return result;
        }
        int start = 0;
        while (start < n)
        {
            int end = start + 1;
            while (end < n && nums[end - 1] + 1 == nums[end])
            {
                ++end;
            }
            if (end == start + 1)
            {
                result.push_back(to_string(nums[start]));
            }
            else
            {
                string interval = to_string(nums[start]) + "->" + to_string(nums[end - 1]);
                result.push_back(interval);
            }
            start = end;
        }
        return result;
    }
};